package com.sinog.core.utilbean;

import lombok.Getter;
import java.io.Serializable;
import java.util.Map;

/**
 * @desc 统一返回值类
 * @author zy
 * @date 2019年6月3日 下午6:30:30
 */
@Getter
public final class Result implements Serializable {

    private static final long serialVersionUID = -898421078217048227L;
    /**
     * 响应码
     */
    private Integer code;
    /**
     * 响应消息
     */
    private String message;
    /**
     * 返回数据
     */
    private Object data;

    public Result() {
    }

    private <T> Result(ReturnCode returnCode,T data) {
        code = returnCode.code();
        message = returnCode.message();
        this.data = data;
    }

    private <T> Result(HnStyleReturnCode returnCode,T data) {
        code = returnCode.code();
        message = returnCode.message();
        this.data = data;
    }

    private <T> Result(Integer code,String message,T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    /**
     * 描述
     * @return Result
     */
    public static Result success() {
        return new Result(ReturnCode.SUCCESS,"");
    }

    /**
     * 描述
     * @param data data
     * @return Result
     */
    public static Result success(Object data) {
        return new Result(ReturnCode.SUCCESS,data);
    }

    /**
     * 返回成功map方法
     * @param data data
     * @return Result
     */
    public static Result success(Map<String,Object> data) {
        return new Result(ReturnCode.SUCCESS,data);
    }

    /**
     * 描述
     * @param data data
     * @return Result
     */
    public static Result failure(Object data) {
        return new Result(ReturnCode.FAILURE,data);
    }

    /**
     * 描述
     * @param code code
     * @param data data
     * @return Result
     */
    public static Result failure(HnStyleReturnCode code,Object data) {
        return new Result(code,data);
    }

    /**
     * 描述
     * @param returnCode returnCode
     * @param data data
     * @return Result
     */
    public static Result failure(ReturnCode returnCode,Object data) {
        return new Result(returnCode,data);
    }

    /**
     * 描述
     * @param returnCode returnCode
     * @return Result
     */
    public static Result failure(ReturnCode returnCode) {
        return new Result(returnCode,"");
    }

    /**
     * 描述
     * @param code code
     * @param message message
     * @param data data
     * @return Result
     */
    public static Result failure(Integer code,String message,Object data) {
        return new Result(code,message,data);
    }
}